package com.zoroki.hmusic.controller;


import com.zoroki.hmusic.constant.MessageConstant;
import com.zoroki.hmusic.entity.Lyrics;
import com.zoroki.hmusic.entity.Result;
import com.zoroki.hmusic.entity.Song;
import com.zoroki.hmusic.service.ILyricsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zoroki
 * @since 2023-05-10
 */
@RestController
@RequestMapping("/lyrics")
@CrossOrigin("*")
@Tag(name = "歌词")
public class LyricsController {
    @Autowired
    private ILyricsService lyricsService;

    @Operation(summary = "添加歌词")
    @PostMapping("/addLyrics")
    @ResponseBody
    public Result addLyrics(@RequestBody Lyrics lyrics) {
        int res = lyricsService.addLyrics(lyrics);
        if (res > 0) {
            return new Result(true, MessageConstant.YES, res);
        }
        return new Result(false, MessageConstant.NO, null);
    }

    @Operation(summary = "更新歌词")
    @PutMapping("/updateLyrics")
    @ResponseBody
    public Result updateLyrics(@RequestBody Lyrics lyrics,@RequestParam String url) {
        Lyrics lyricsRes = lyricsService.updateLyrics(lyrics,url);
        if (lyricsRes != null) {
            return new Result(true, MessageConstant.YES, lyricsRes);
        }
        return new Result(false, MessageConstant.NO, null);
    }

    @Operation(summary = "根据id获取歌词")
    @GetMapping("/getLyricsById")
    @ResponseBody
    public Result getLyricsById(@RequestParam int id) {
        Lyrics lyrics = lyricsService.getLyricsById(id);
        if (lyrics != null) {
            return new Result(true, MessageConstant.YES, lyrics);
        }
        return new Result(false, MessageConstant.NO, null);
    }
}
